package com.freewater.javabase.demo.datetime;

import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class InstantDemo {
    public static void main(String[] args) {
        Instant start = Instant.now();
        // do something here
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        Instant end = Instant.now();
        System.out.println(Duration.between(start, end).toMillis());
        // Date与Instant互转
        Instant nowInstant = new Date().toInstant();
        System.out.println(nowInstant.getEpochSecond());
        Date time1 = new Date(Instant.now().toEpochMilli());
        System.out.println(time1);
    }
}
